<?php
class RecommendPsytest extends CWidget {
    public $topic;

	public function init() {
		$optionName = 'recommendPsytest';
		$option = Options::model()->findOptionByName($optionName);
		$recommendPsytestIds = explode(',', $option->optionValue);
        $topicId = (int)$recommendPsytestIds[array_rand($recommendPsytestIds)];
        $this->topic = TestTopics::model()->findByPk($topicId);
	}

	public function run() {
        if($this->topic !== null) {
            $this->renderContent();
        }
	}

	public function renderContent() {
		return $this->render('recommend-psytest', array('topic' => $this->topic)); 
	}
}
